package com.chance.cc.crawler.development.bootstrap.qimai;

import org.apache.commons.lang3.time.DateUtils;
import org.junit.Test;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @ClassName song
 * @Description TODO
 * @Author ding
 * @Date 2021/9/7 14:23
 * @Version 1.0
 **/
public class Computer {


    @Test
    public void test(){
        Calendar cal=Calendar.getInstance();
        cal.set(Calendar.MONTH,cal.get(Calendar.MONTH)-1);
        Date day = cal.getTime();
        String str = new SimpleDateFormat("yyyy-MM-dd").format(day);
        try {
            Long time = DateUtils.parseDate(str,"yyyy-MM-dd").getTime();
            time = time + 100000000l;
            String sdate1 = String.valueOf(new Timestamp(time));
            String date = sdate1.substring(0,11);//上个月零点零分零秒的毫秒数
            String sdate = date + "00:00:00";
            Long edate1 = System.currentTimeMillis();
            edate1 = edate1 - 100000000l;
            String edate = String.valueOf(new Timestamp(edate1));
            String date1 = edate.substring(0,11);//昨天
            edate = date1 +"23:59:59";//今天23点59分59秒的毫秒数
            System.out.println(sdate);
            System.out.println(edate);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        System.out.println(str);
        cal.add(Calendar.DATE, -1);    //得到前一天

        cal.add(Calendar.MONTH, -1);    //得到前一个月
        int  year = cal.get(Calendar.YEAR);
        System.out.println(year);
        int  month = cal.get(Calendar.MONTH)+1;
        System.out.println(month);
        long date = cal.getTimeInMillis();

    }
}
